<template>
  <div class="app-container">
    <el-dialog :title="title" :visible.sync="open" width="1080px" append-to-body v-drag-fullscreen>
    <el-form :model="queryParams" ref="queryForm" v-show="showSearch" label-width="68px" class="form-flex">
      <el-row :gutter="20">
        <el-col :span="6" :xs="24">
          <el-form-item label="催缴人" prop="requireUser">
            <el-input
              v-model="queryParams.requireUser"
              placeholder="请输入催缴人"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6" :xs="24">
          <el-form-item label="催缴时间" prop="requireTime">
            <el-date-picker clearable size="small"
                            v-model="queryParams.requireTime"
                            type="date"
                            value-format="yyyy-MM-dd"
                            placeholder="选择生效时间">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="6" :xs="24">
          <el-form-item label="催缴方式" prop="requireType">
            <el-select v-model="queryParams.requireType" placeholder="请选择催缴方式" clearable size="small">
              <el-option
                v-for="item in dict.require_type"
                :key="item.dictValue"
                :label="item.dictLabel"
                :value="item.dictValue"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6" :xs="24">
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <el-table v-loading="loading" :data="requirePayList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="催缴人" align="center" prop="requireUser" />
      <el-table-column label="催缴时间" align="center" prop="requireTime"/>
      <el-table-column label="催缴方式" align="center" prop="requireType" >
        <template slot-scope="scope">
          {{ dict.label.require_type[scope.row.requireType] }}
        </template>
      </el-table-column>
      <el-table-column label="催缴条数" align="center" >
        <template slot-scope="scope">
          成功(<el-link style="color: royalblue" @click="winClick(scope.row)">{{scope.row.win}}</el-link>)失败(<el-link style="color: #ff4949" @click="loseClick(scope.row)">{{scope.row.lose}}</el-link>)
        </template>
      </el-table-column>
      <el-table-column label="催缴内容" align="center" prop="requireContent" show-overflow-tooltip>
        <template slot-scope="scope">
          <span v-html="scope.row.requireContent"></span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    </el-dialog>
    <require-record ref="record"/>
  </div>
</template>

<script>

  import { listMixin } from "@/utils/mixins/listMixin";
  import { listRequirePay, exportRequirePay } from "@/api/payfee/requirePay";
  import RequireRecord  from "./RequireRecord"
  export default {
    name: "RequirePay",
    mixins:[ listMixin ],
    components:{RequireRecord},
    dicts: [   'require_type',   ],
    data() {
      return {
        // 催缴管理表格数据
        requirePayList: [],
        open:false,
        // 弹出层标题
        title: "",
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          requireUser: null,
          requireTime: null,
          requireType: null,
          requireContent: null
        },
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询催缴管理列表 */
      show(option){
        this.loading = true;
        listRequirePay(this.queryParams).then(response => {
          this.requirePayList = response.rows;
          this.total = response.total;
          this.loading = false;
          this.open = true;
          this.title = "查看催缴记录";
        });
      },
      getList() {
        listRequirePay(this.queryParams).then(response => {
          this.requirePayList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有催缴管理数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportRequirePay(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
      },
      winClick(row){
        this.$refs.record.show({requireId:row.id,status:'10'});
      },
      loseClick(row){
        this.$refs.record.show({requireId:row.id,status:'20'});
      }
    }
  };
</script>
